﻿using LayuiMvc.DataEntity;
using LayuiMvc.DataEntity.DataEntity;
using LayuiMvcUtil.Exception;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LayuiMvc.Logic.Community
{
   public class FileService
    {
        #region 文件管理==保存文件
        /// <summary>
        /// 保存文件信息至数据库
        /// </summary>
        /// <param name="savaEntity">需要保存的文件实体类</param>
        /// <returns></returns>
        public async Task SaveFile(FileEntity savaEntity)
        {
            using (EFContext db = new EFContext())
            {
                db.Entry(savaEntity).State = EntityState.Added;

                int affectLineCount = await db.SaveChangesAsync();
                if (affectLineCount==0)
                {
                    throw new CustomException("文件保存失败");
                }
            }
        }
        #endregion
    }
}
